# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocp-index
pkgver=1.3.3
pkgrel=0
pkgdesc="Lightweight completion and documentation browsing for OCaml libraries"
url="http://www.typerex.org/ocp-index.html"
arch="all !riscv64"  # limited by ocaml aport
license="LGPL-2.1-only-WITH-linking-exception AND GPL-3.0-only"
_depends_ocaml="ocaml-runtime ocaml-ocp-indent ocaml-re"
depends_dev="
	ocaml-cmdliner-dev
	ocaml-compiler-libs
	ocaml-ocp-indent-dev
	ocaml-re-dev
	"
makedepends="$depends_dev dune ocaml ocaml-cppo"
subpackages="
	$pkgname-doc
	$pkgname-emacs::noarch
	$pkgname-vim::noarch
	ocaml-$pkgname-dev:_libdev
	ocaml-$pkgname:_lib
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/OCamlPro/ocp-index/archive/refs/tags/$pkgver.tar.gz"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build -p ocp-index --verbose
}

check() {
	dune runtest -p ocp-index --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		ocp-index
}

emacs() {
	pkgdesc="$pkgdesc in Emacs"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"

	amove usr/share/emacs
}

vim() {
	pkgdesc="$pkgdesc in vim"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	amove usr/share/ocp-index/vim
}

_libdev() {
	pkgdesc="$pkgdesc (development files)"
	depends="$depends_dev ocaml-$pkgname=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; for path in $(find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done

}

_lib() {
	pkgdesc="$pkgdesc (library)"
	depends="$_depends_ocaml"

	amove usr/lib/ocaml
}

sha512sums="
6360240c951ac64baf9b3736c9a37c41a5ac8c5ddf52e723019fb5ef294e786e245712fd88f408bd8f6881d8741ab152872181062acd81443eec07d1d703e85a  ocp-index-1.3.3.tar.gz
"
